fn main() {
    // 空字符串
    let mut s = String::new();

    let data = "initial contents";

    let s = data.to_string();

    let s = "initial contents".to_string();
    let s = String::from("initial contents");

    // 字符串是 UTF-8 编码
    // let hello = String::from("السلام عليكم");
    // let hello = String::from("Dobrý den");
    // let hello = String::from("Hello");
    // let hello = String::from("שָׁלוֹם");
    // let hello = String::from("नमस्ते");
    // let hello = String::from("こんにちは");
    // let hello = String::from("안녕하세요");
    // let hello = String::from("你好");
    // let hello = String::from("Olá");
    let hello = String::from("Здравствуйте");
    // let hello = String::from("Hola");

    // 更新字符串,push_str()，不需要参数的所有权。push(),添加单独的字符
    let mut s1 = String::from("foo");
    s1.push_str("bar");
    println!("{},{},{}", s, hello, s1);

    // 字符串相加 + ，获取第一个参数的所有权，第二个参数的引用
    let s4 = String::from("Hello, ");
    let s5 = String::from("World!");
    let s6 = s4 + &s5; // s4被移动，不能再用

    println!("{s6}");
    // 字符串相加 format! 宏，使用引用不获取权限
    let s7 = String::from("tic");
    let s8 = String::from("tac");
    let s9 = String::from("toe");

    let k = format!("{s7}-{s8}-{s9}");
    println!("{k}");

    //String 不支持下标
    let sh = &hello[0..4];
    println!("{sh}");

    // 遍历打印字符
    for c in hello.chars() {
        println!("{c}");
    }

    // 遍历打印字节
    for b in hello.bytes() {
        println!("{b}");
    }
}
